package com.chenbei.system.vo.resp;

import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Schema(description = "管理员用户菜单响应")
@Data
public class AdminUserMenuResp {

    @Schema(description = "主键ID")
    private Long id;

    @Schema(description = "路由名称")
    private String name;

    @Schema(description = "路由地址")
    private String path;

    @Schema(description = "图标")
    private String icon;

    @Schema(description = "菜单类型[1:目录|2:菜单项|3:按钮]")
    private Integer type;

    @Schema(description = "元数据")
    private MenuMeta meta;

    @Schema(description = "组件地址")
    private String component;

    @Schema(description = "子路由")
    private List<AdminUserMenuResp> children;

    public String getName() {
        if (StrUtil.isBlank(name) && StrUtil.isNotBlank(path)) {
            String[] split = path.split("/");
            return Arrays.stream(split).filter(StrUtil::isNotBlank).map(str -> str.substring(0, 1).toUpperCase() + str.substring(1)).collect(Collectors.joining());
        }
        return name;
    }
}
